using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Threading;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Aspx.Manager.Lib;
using Dimok.Data.Database;
using Dimok.Data;
using Dimok.Exceptions;
using Data;

namespace Dimok.Aspx.Manager.Application
{
	/// <summary>
	/// Summary description for Application.
	/// </summary>
	public partial class Application : Page_AL{
		#region Controls
		protected System.Web.UI.HtmlControls.HtmlGenericControl txtDealership;
		protected System.Web.UI.HtmlControls.HtmlGenericControl txtDealerPhone;
		protected System.Web.UI.HtmlControls.HtmlGenericControl txtDealerFax;
		protected System.Web.UI.WebControls.Literal ltrApplID;
		#endregion Controls
	
		protected void Page_Load(object sender, System.EventArgs e){
			Response.Cache.SetCacheability(HttpCacheability.NoCache);
			DataSet dsAI1 = null;
			try{
				if( !uox.hasApplID ){// If no ApplID assume that new applicant is required
					int aID = uox.AddApplicant(uox.menuID);
					Context.Response.Redirect("/manager/menu/showapplicant.aspx?"+UOX.APPL_ID_PARAM+"="+aID+"&"+Request.QueryString);
					return;
				}
				
				SQL.SELECT(selDealers,db,SQL.Dealers_V,"Name","ID");
				SQL.SELECT(selSalesPersons,uox.DealerSalesPersons(),"Name","ID");

				ltrApplInfo.Text = SQL.XmlInnerText(uox.ApplInfo.Row());
				ltrApplInfoCo.Text = SQL.XmlInnerText(uox.db,"SELECT * FROM Borrower(@LoanID,1)",uox.applID);

				DataSet dsAI = SQL.AddrInfo(uox.db,uox.applID,0);
				dsAI1 = SQL.AddrInfo(uox.db,uox.applID,1);
				ltrAddrInfo_0.Text = SQL.XmlInnerText(dsAI);
				ltrAddrInfo_1.Text = SQL.XmlInnerText(dsAI1);
				Trace.Write("GetCitiesByZip (Start)");
				ltrCities.Text = SQL.GetCitiesByZip(uox.dbADO,dsAI.Tables[0].Rows[0]["Zip"]+"");
				Trace.Write("GetCitiesByZip");
				if(dsAI1.Tables[0].Rows.Count > 0 && dsAI1.Tables[0].Rows[0]["Zip"] != System.DBNull.Value )
					ltrCities1.Text = SQL.GetCitiesByZip(uox.dbADO,dsAI1.Tables[0].Rows[0]["Zip"]+"");

				Trace.Write("EmplInfo Start");
				ltrEmplInfo_0.Text = SQL.XmlInnerText(SQL.EmplInfo(uox.db,uox.applID,0,0,0));
				Trace.Write("EmplInfo 0");
				ltrEmplInfo_1.Text = SQL.XmlInnerText(SQL.EmplInfo(uox.db,uox.applID,0,0,1));
				Trace.Write("EmplInfo 1");
				ltrEmplInfoCo_0.Text = SQL.XmlInnerText(SQL.EmplInfo(uox.db,uox.applID,1,0,0));
				Trace.Write("Co-EmplInfo 0");
				ltrEmplInfoCo_1.Text = SQL.XmlInnerText(SQL.EmplInfo(uox.db,uox.applID,1,0,1));
				Trace.Write("Co-EmplInfo 1");
				
				ltrStates1.Text = ltrStates.Text = SQL.ADOToString(uox.dbADO,"SELECT StateCode t, StateCode v FROM ts_State");
				ltrUsableIncomeCo.Text = ltrUsableIncome.Text = SQL.ADOToString(uox.dbADO,SQL.NonEmploymentIncomeSQL);
				ltrResidence.Text = SQL.ADOToString(uox.dbADO,"SELECT ID AS v, Name AS t FROM  ts_HouseHoldType ORDER BY Name");

				ltrWorkFlow_F.Text = uox.MenusNext;
				Trace.Write("MenuNext");
				ltrWorkFlow_B.Text = uox.MenusPrev;
				Trace.Write("MenuPrev");
			}catch(ThreadAbortException){
			}catch(Exception exp){
				throw new ClientException(exp);
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion
	}
}
